<?php

namespace App\Http\Exports;

use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use App\Model\Base;

class QueryExportNotpaiedList implements FromQuery,WithHeadings,WithMapping
{

    use Exportable;

    public function __construct($param)
    {
        $this->param = $param;
    }

    public function query()
    {
        $param = $this->param;
        $map['deliver_state'] = 1;//已经发货的
        $map['state'] = 1;//没有支付的
        if(!empty($param['star_date']) && !empty($param['end_date'])){
            return Base::query()->from('user_order')->orderBy('send_goods_time')->whereBetween('create_time',[$param['star_date'],$param['end_date']])->where($map);
        }else{
            return Base::query()->from('user_order')->orderBy('send_goods_time')->where($map);
        }



    }

    public function headings(): array
    {
        return [
          '出荷日',
          '会社名',
          '納品先',
          '受注No',
          '価格',
        ];
    }

    public function map($invoice):array
    {
        return [
            $invoice->send_goods_time,
            fun_corp($invoice->corp_id),
            fun_shop($invoice->shop_id),
            $invoice->order_id,
            $invoice->money,
        ];
    }

}
